"""
@FileName：core_config.py
@Author：Huterox
@Description：Go For It
@Time：2024/4/4 16:44
@Copyright：©2018-2024 awesome!
"""

# =============================================================================
# Config
# =============================================================================
import contextlib


class Config:
    enable_backprop = True
    train = True


@contextlib.contextmanager
def using_config(name, value):
    old_value = getattr(Config, name)
    setattr(Config, name, value)
    try:
        yield
    finally:
        setattr(Config, name, old_value)


def no_grad():
    return using_config('enable_backprop', False)


def test_mode():
    return using_config('train', False)